package com.briup.test;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class TuesdayFinder {
    public static List<LocalDate> findTuesdays(LocalDate start, LocalDate end) {
        List<LocalDate> tuesdays = new ArrayList<>();
        // 从起始日期开始，找到第一个星期二
        LocalDate current = start;
        while (current.getDayOfWeek() != DayOfWeek.TUESDAY) {
            current = current.plusDays(1);
            if (current.isAfter(end)) {
                return tuesdays; // 范围内没有星期二
            }
        }
        // 依次加7天，收集所有星期二
        while (!current.isAfter(end)) {
            tuesdays.add(current);
            current = current.plusWeeks(1);
        }
        return tuesdays;
    }
    public static void main(String[] args) {
        // 示例：查找2025-11-01到2025-11-30之间的星期二
        LocalDate start = LocalDate.of(2025, 11, 1);
        LocalDate end = LocalDate.of(2025, 11, 30);
        List<LocalDate> result = findTuesdays(start, end);

        System.out.println("起止日期内的星期二：");
        result.forEach(System.out::println);
    }
}